package cn.edu.gzgs.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 菜单实体（前端权限控制）
 */
// @Entity // Removed JPA @Entity
// @Table(name = "menu") // Removed JPA @Table
@TableName("menu") // MyBatis-Plus annotation
@Data
public class Menu {
    // @Id // Removed JPA @Id
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    // @Column(nullable = false, length = 64) // Removed JPA @Column
    private String name;

    // @ManyToOne // Removed JPA relationship
    // @JoinColumn(name = "parent_id") // Removed JPA relationship
    @TableField(exist = false) // Marking 'parent' object field as not a DB column for MP
    private Menu parent; // 父级菜单 - Use Long parentId for DB mapping

    @TableField("parent_id") // Explicitly map to parent_id column in DB
    private Long parentId;

    // @Column(name = "sort_num", nullable = false) // Removed JPA @Column
    private Integer sortNum = 0; // 排序值

    // @Column(name = "menu_key", nullable = false, unique = true, length = 64) // Removed JPA @Column
    private String menuKey; // 前端唯一标识

    @TableField(fill = FieldFill.INSERT) // Added annotation
    private LocalDateTime createdTime;

    @TableField(fill = FieldFill.INSERT_UPDATE) // Added annotation
    private LocalDateTime updatedTime;

    // @PrePersist // Removed annotation and method
    // protected void onCreate() {
    //     if (createdTime == null) {
    //         createdTime = LocalDateTime.now();
    //     }
    //     if (updatedTime == null) {
    //         updatedTime = LocalDateTime.now();
    //     }
    // }

    // @PreUpdate // Removed annotation and method
    // protected void onUpdate() {
    //     updatedTime = LocalDateTime.now();
    // }
}
